package start.spring.basic.logs.controller.lctest;

import java.text.ParseException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.support.SendResult;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import start.spring.basic.dynamic.DynamicKafkaDAO;
import start.spring.basic.log.ServiceLog;
import start.spring.basic.logs.common.LogsConsumerConstant;

/**
 *
 * ****************************************************************************
 * 流程测试入口
 *
 * @author(作者)：xuyongyun
 * @date(创建日期)：2021年10月1日
 ******************************************************************************
 */
@Slf4j
@RestController
@RequestMapping("/lctest")
@Api(tags = "传输流程测试接口")
public class LctestController {

	@Autowired
	DynamicKafkaDAO kafkaDAO;

	@ServiceLog(businessType = "发送消息到指定的kafka队列", systemType = LogsConsumerConstant.SYSTEM_TYPE, recordResult = false, userId = "")
    @RequestMapping(value = "/send", method = {RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "发送消息到指定的kafka队列", notes = "")
    public void ywqConsumer(String kafkaId,String topic,@RequestBody String record) throws ParseException {
		ListenableFuture<SendResult<String, String>> SendResult = kafkaDAO.send(kafkaId, topic, record);
		try {
			log.info(SendResult.get().getProducerRecord().toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
    }

}
